<template>
  <van-goods-action>
    <van-goods-action-icon
      :icon="iscollected ? 'star' : 'star-o'"
      :text="iscollected ? '已收藏' : '未收藏'"
      :color="iscollected ? '#ee0a24' : '#666'"
      @click="iscollected_click"
    />
    <van-goods-action-icon
      icon="cart-o"
      text="购物车"
      :badge="login ? goodsCount : 0"
      @click="$router.push('/cart')"
    />
    <van-goods-action-button type="danger" text="立即购买" @click="ForBuy" />
    <van-goods-action-button
      color="#FFC51D"
      type="danger"
      text="加入购物车"
      @click="changeSkuShow"
    />
  </van-goods-action>
</template>

<script>
export default {
  props: ["goodsCount"],
  data() {
    return { iscollected: false, login: false };
  },
  created() {
    let token = localStorage.getItem("token");
    if (token) {
      this.login = true;
    }
  },
  methods: {
    //立即购买
    ForBuy() {
      let token = localStorage.getItem("token");
      if (!token) {
        this.$router.push("/user");
        this.$toast("请先登录");
        this.$router.go(-1)
      }
      this.$router.push("/cart");
    },
    changeSkuShow() {
      //   console.log(123);
      this.$emit("changeSkuShow");
    },
    iscollected_click() {
      // let token = localStorage.getItem("token");
      // if (!token) {
      //   this.$toast("亲，请先登录，哈哈");
      //   this.$router.push("/user");
      //   return;
      // }
      let mustbeLogin = this.utils.mustbeLogin();
      if (!mustbeLogin) return;
      this.iscollected = !this.iscollected;
    },
  },
};
</script>
 
<style lang = "less" scoped>
.van-goods-action {
  z-index: 9999;
}
</style>